package com.unknowpupil.sell.controller;

import com.unknowpupil.sell.common.BasePage;
import com.unknowpupil.sell.common.request.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Classname: WxAuthController
 * @Author: <a> w10g </a>
 * @CreateDate: Create in 2019/12/31 13:56
 * @Description:
 * @Version: 1.0
 */
@Api(tags = {"ProductInfo"}, description = "商品表模块不用")
@RestController
@RequestMapping(value = "/wx/")
@Slf4j
public class WxAuthController {
    final static String get_access_token = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxb435f9a8e1fe928c&secret=d0bff10ab43937bd02e75d5d89a82e22&code=023bGm8g1axKuu0so79g1dMr8g1bGm8S&grant_type=authorization_code";

    @GetMapping("oauth")
    public Result oauth(@RequestParam("code") String code) {
        log.info("进入oauth方法");
        log.info("获取code = {} ", code);
        //得到所有商品
        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxb435f9a8e1fe928c&secret=d0bff10ab43937bd02e75d5d89a82e22&code=" + code + "&grant_type=authorization_code";
        RestTemplate restTemplate = new RestTemplate();
        String str = restTemplate.getForObject(url, String.class);
        log.info("获取access_token  = {} ", str);
        return Result.ok(str);
    }
}
